﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Prism.WebBuilder.Lib.CArgs
{
	public sealed class CArgsProvider
	{
		public dynamic Args { get; private set; }

		public List<string> PlainArgs {get; private set;}

		public CArgsProvider(IEnumerable<string> args)
		{
			ParseArgs(args);
		}

		public void ParseArgs(IEnumerable<string> args)
		{
			Args = new CArgsCollection();
			PlainArgs = new List<string>();

			foreach (var arg in args)
			{
				if (arg.StartsWith("-"))
				{
					string name;
					string value;
					ParseArg(arg, out name, out value);


					if (string.IsNullOrEmpty(value))
						Args[name] = true;
					else
						Args[name] = value;
				}
		
				else
				{
					PlainArgs.Add(arg);
				}

			}
		}

		private void ParseShortArgument(string arg)
		{
		}
		private void ParseArgument(string name, string value)
		{
		}

		private void ParseArg(string arg, out string name, out string value)
		{
			string[] parsedArg = arg.Split('=');
			if (parsedArg.Length > 0)
			{
				name = parsedArg[0].TrimStart('-');
				if (parsedArg.Length > 1)
					value = parsedArg[1];
				else
					value = "";
			}
			else
			{
				name = "";
				value = "";
			}
		}
	}
}
